package com.appleyk.mapping;

import com.appleyk.query.DepartmentQuery;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class DepartmentMapping {

    @Resource
    private DepartmentQuery departmentQuery;

    /**
     * 查询 部门 详情
     * @return 详情
     */
    public String getDepartments(List<String> reStrings){
        String depName = reStrings.get(1);
        String departments = departmentQuery.getDepartments(reStrings.get(1));
        if(StringUtils.isNotEmpty(departments)){
            return depName + ", " + departments;
        }
        return null;
    }

    /**
     * 查询 部门 人数
     * @return 人数
     */
    public String getDepartmentsEmpNumber(List<String> reStrings){
        String depName = reStrings.get(1);
        String departments = departmentQuery.getDepartmentsEmpNumber(depName);
        if(StringUtils.isNotEmpty(departments)){
            return depName + "一共有：" + departments+" 人";
        }
        return null;
    }

    /**
     * 查询 部门 有哪些人
     * @return 有哪些人
     */
    public String getDepHaveEmp(List<String> reStrings){
        String depName = reStrings.get(1);
        List<String> departmentsEmp = departmentQuery.getDepHaveEmp(depName);
        if(CollectionUtils.isNotEmpty(departmentsEmp)){
            return String.join("\n",departmentsEmp);
        }
        return null;
    }

    /**
     * 查询 部门 有哪些岗位
     * @return 有哪些岗位
     */
    public String getDepHavePosName(List<String> reStrings){
        String depName = reStrings.get(1);
        List<String> departmentsPosName = departmentQuery.getDepHavePosName(depName);
        if(CollectionUtils.isNotEmpty(departmentsPosName)){
            return String.join("\n",departmentsPosName);
        }
        return null;
    }


}
